<template>
    <div>
        <el-form
                ref="dataForm"
                status-icon
                :model="form"
                :rules="rules"
                label-width="0px"
        >
            <el-descriptions
                    title="任务发起"
                    :column="3"
                    border
            >
                <el-descriptions-item>
                    <template slot="label"> 筛查年度</template>
                    <el-form-item prop="years" label="">
                        <el-input v-model="form.years" style="width: 100%" clearable></el-input>
                    </el-form-item>
                </el-descriptions-item>

                <el-descriptions-item>
                    <template slot="label"> 开始时间</template>
                    <el-form-item label="" prop="start_time">
                        <el-date-picker
                                type="date"
                                placeholder="选择日期"
                                v-model="form.start_time"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                style="width: 100%"
                                clearable
                        ></el-date-picker>
                    </el-form-item>
                </el-descriptions-item>

                <el-descriptions-item>
                    <template slot="label"> 结束时间</template>
                    <el-form-item label="" prop="over_time">
                        <el-date-picker
                                type="date"
                                placeholder="选择日期"
                                v-model="form.over_time"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                style="width: 100%"
                                clearable
                        ></el-date-picker>
                    </el-form-item>
                </el-descriptions-item>

                <el-descriptions-item>
                    <template slot="label"> 年度任务量</template>
                    <el-form-item prop="task_count_number" label="">
                        <el-input v-model="form.task_count_number" style="width: 100%" clearable></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item></el-descriptions-item>
                <el-descriptions-item></el-descriptions-item>
            </el-descriptions>

            <el-descriptions :column="1" border>
                <el-descriptions-item labelStyle="width: 13%" contentStyle="width: 87%">
                    <el-form-item label=" ">
                        <el-button @click="handleDialogVisible(false)" size="small"
                        >取 消
                        </el-button
                        >
                        <el-button
                                type="primary"
                                @click="!form.id ? create() : update()"
                                size="small"
                        >确 定
                        </el-button>
                    </el-form-item>
                </el-descriptions-item>
            </el-descriptions>
        </el-form>

    </div>
</template>

<script>
    import {createTask, updateTask} from "@/api/task/task";
    export default {
        props: ["rowData", "dialogStatus"],
        components: {},
        data() {
            return {
                form: {
                    id: "",
                    years: "",
                    start_time: "",
                    over_time: "",
                    task_count_number: "",
                },
                rules: {
                },
                createLoading: false,
                updateLoading: false,
            };
        },
        created() {
            if (this.dialogStatus == "update") {
                this.form = {...this.rowData};
            }
        },
        methods: {
            //父页面的回调事件
            handleDialogVisible(isUpdate) {
                this.dialogVisible = false;
                this.$emit("childByDialogVisible", this.dialogVisible, isUpdate);
            },
            //创建
            create() {
                this.$refs["dataForm"].validate((valid) => {
                    if (valid) {
                        this.createLoading = true;
                        createTask(this.form).then((response) => {
                            this.createLoading = false;
                            if (response.code == 200) {
                                this.msgSuccess(response.msg);
                                this.handleDialogVisible(true);
                            }
                        });
                    }
                });
            },
            //修改
            update() {
                this.$refs["dataForm"].validate((valid) => {
                    if (valid) {
                        this.updateLoading = true;
                        updateTask(this.form).then((response) => {
                            this.updateLoading = false;
                            if (response.code == 200) {
                                this.msgSuccess(response.msg);
                                this.handleDialogVisible(true);
                            }
                        });
                    }
                });
            },
        },
        watch: {
        },
    };
</script>
<style lang="scss" scoped="scoped">
    .el-form-item {
        margin: 0px;
    }
</style>
